<template>
  <nav>
    <div class="munber1"><p>2</p></div>
    <i @click="$router.push('/order')">订单</i>
    <div id="car" @click="$router.push('/car')">
      <div class="munber">
        <p>{{ num.conut }}</p>
      </div>
      <img src="@/assets/images/car.png" alt="" />
    </div>
    <p @click="$router.push('/person')">个人中心</p>
    <p @click="$router.push('/')" class="mainpage">首页</p>
  </nav>
  <div id="box">
    <div id="headerImg">
      <div id="img"></div>
    </div>
    <div class="headerBox">
      <br /><br />
      <div class="goods-image">
        <!-- 大图 -->
        <div
          v-show="show"
          class="large"
          :style="[
            { backgroundImage: `url(${goods.imgs})` },
            largePosition,
          ]"
        ></div>
        <!-- 中图 -->
        <div class="middle" ref="target">
          <img :src="goods.imgs" alt="" />
          <!-- 遮罩色块 -->
          <div v-show="show" class="layer" :style="layerPosition"></div>
          <p>【商品名称】：{{goods.goodsName}}</p>
        </div>
        <!-- 小图 -->
        <ul class="small">
          <li><img :src="goods.imgs"/></li>
          <li><img :src="goods.imgs"/></li>
          <li><img :src="goods.imgs"/></li>
        </ul>
      </div>
      <div class="msg">
        <ul>
          <li>商品数量：500g</li>
          <li>商品价钱：<b>{{goods.marketprice}}元</b> &nbsp; {{goods.realprice}}元</li>
          <li>商品产地：{{goods.address}}</li>
          <li>售后说明：次日送达|极速退款|72小时品质无忧</li>
          <li>提货信息：重庆工程学院前门，今日下单预计明日10:00可自提</li>
          <li>
            保质期：5天 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
            <el-button type="success" size="large" id="btn" @click="$router.push({name:'carView',query:{data1:JSON.stringify(goods)}})"
              ><img src="@/assets/images/car1.png" alt="" />&nbsp;
              加入购物车</el-button
            >
            <el-button
              type="success"
              size="large"
              plain
              id="btn2"
              @click="toPay()"
              >立即购买</el-button
            >
          </li>
          <li>
            <div class="count">
              数量： <span class="add" @click="goods.count > 1 ? (goods.count -= 1) : 1"> - </span>
              <span class="input"
                ><input type="text" v-model="goods.count"/></span>
              <span class="add" @click="goods.count++">+</span> 份
            </div>
          </li>
        </ul>
      </div>
      <br /><br />

      <hr />
      <div class="g-service">
        <h3>店铺名：<i>{{goods.shopName}}铺</i></h3>
        <dl>
          <br />
          <dt>【促销】</dt>
          <dd>
            12月好物放送，App领券购买直降120元
            <a href="javascript:;">了解详情</a>
          </dd>
        </dl>
        <dl>
          <dt>【保险】</dt>
          <dd>
            品质险由中国人民保财险承担 <a href="javascript:;">了解详情</a>
          </dd>
        </dl>
      </div>
      <ul class="goods-sales">
        <li>
          <p><img src="@/assets/images/33.png" />&nbsp; 销量</p>
          <p>200+</p>
          <p><a href="#">销量人气</a></p>
        </li>
        <li>
          <p><img src="@/assets/images/11.png" />&nbsp; 评价</p>
          <p>400+</p>
          <p><a href="#"> 查看评价</a></p>
        </li>
        <li>
          <p><img src="@/assets/images/22.png" />&nbsp; 收藏</p>
          <p>600+</p>
          <p><a href="#">收藏商品</a></p>
        </li>
      </ul>
    </div>
     <el-footer>
         <div id="imgfooter2">
             <p>自建物流 | 服务保障 | 质量保证</p>
             <p><img src="@/assets/images/footer.png">
             <img src="@/assets/images/footer1.png">
             <img src="@/assets/images/footer2.png">
             <img src="@/assets/images/footer3.png">
             <img src="@/assets/images/footer4.png"></p>
             </div>
             <!-- <hr> -->
        <footer>
        <div class="row justify-content-center">
          <p id="p1">合作伙伴</p>
        </div>
         <div class="row justify-content-md-center">
          <span id="p2">企业培训| 合作事项| 版权投诉</span>
        </div>
        <div class="row justify-content-md-center">
          <p id="p3">渝ICP  备1378633 @2019-2-2222 jxsxndjdd  Pnsaxx by sxcjhx</p>
        </div>
        </footer>
    </el-footer>
  </div>
  <!-- 弹窗支付 -->
  <transition>
    <div class="el-overlay is-message-box" v-if="pageShow">
      <div class="addpage">
        <my-pay @closeclick="closeclick"></my-pay>
      </div>
    </div>
  </transition>
</template>
<script>
import { useRoute } from 'vue-router'
import { ElMessage } from 'element-plus'
import { reactive, ref, watch, onMounted } from 'vue'
import { useMouseInElement } from '@vueuse/core'
import MyPay from './popWindows/myPay.vue'
// import router from '@/router'
export default {
  name: 'goodsDetials',
  components: { MyPay },
  setup (props, context) {
    // 当前预览图的索引
    const currIndex = ref(0)
    // 1. 是否显示遮罩和大图
    const show = ref(false)
    // 2. 遮罩的坐标(样式)
    const layerPosition = reactive({
      left: 0,
      top: 0
    })
    // 3. 大图背景定位(样式)
    const largePosition = reactive({
      backgroundPositionX: 0,
      backgroundPositionY: 0
    })
    // 4. 使用useMouseInElement得到基于元素左上角的坐标和是否离开元素数据
    const target = ref(null)
    const { elementX, elementY, isOutside } = useMouseInElement(target)
    watch([elementX, elementY, isOutside], () => {
      // 5. 根据得到数据设置样式数据和是否显示数据
      show.value = !isOutside.value
      // 计算坐标
      const position = { x: 0, y: 0 }

      if (elementX.value < 100) position.x = 0
      else if (elementX.value > 300) position.x = 200
      else position.x = elementX.value - 100

      if (elementY.value < 100) position.y = 0
      else if (elementY.value > 300) position.y = 200
      else position.y = elementY.value - 100
      // 给样式赋值
      layerPosition.left = position.x + 'px'
      layerPosition.top = position.y + 'px'
      largePosition.backgroundPositionX = -2 * position.x + 'px'
      largePosition.backgroundPositionY = -2 * position.y + 'px'
    })

    // 接收数据
    const route = useRoute()
    const goods = reactive({ imgs: '', realprice: '', shopName: '', goodsName: '', address: '', marketprice: '', count: '' })
    onMounted(() => { // route.query.data1接收参数
      goods.imgs = JSON.parse(route.query.data1).imgs
      goods.realprice = JSON.parse(route.query.data1).realprice
      goods.shopName = JSON.parse(route.query.data1).shopName
      goods.goodsName = JSON.parse(route.query.data1).goodsName
      goods.address = JSON.parse(route.query.data1).address
      goods.count = JSON.parse(route.query.data1).count
      goods.marketprice = JSON.parse(route.query.data1).marketprice
      console.log(route.query.data1, '0000')
    })

    const number = reactive({ conut1: 1 })
    function sub () {
      // eslint-disable-next-line no-unused-expressions
      number.conut1 > 1 ? (number.conut1 -= 1) : 1
    }
    function add () {
      number.conut1 += 1
    }
    const num = reactive({ conut: 1 })
    function addToCar () {
      num.conut += number.conut1
      ElMessage({
        message: '添加成功！',
        type: 'success'
      })
    }

    // 弹窗
    const pageShow = ref(false)
    function toPay () {
      pageShow.value = true
    }
    // 关闭弹窗
    function closeclick (isclose) {
      if (isclose == false) {
        pageShow.value = false
        // console.log(xxxx)
      }
    }

    return {
      currIndex,
      show,
      layerPosition,
      largePosition,
      target,
      addToCar,
      num,
      number,
      sub,
      add,
      closeclick,
      toPay,
      pageShow,
      goods
    }
  }
}
</script>
   <style scoped>
#box {
  background-color: rgb(236, 234, 229);
}
#headerImg {
  width: 100%;
  height: 120px;
  background-image: url(~@/assets/images/img.jpg);
  background-size: cover;
  margin-bottom: -30px;
}
#headerImg > #img {
  background-color: rgb(207, 203, 203, 0.7);
  width: 100%;
  height: 120px;
}
.input > input {
  width: 50px;
  height: 20px;
  font-size: 16px;
  text-align: center;
}
.add {
  border: 1px solid rgb(90, 88, 88);
  height: 20px;
  background-color: darkgrey;
}
.add:hover {
  border: 1px solid red;
}
.goods-image {
  width: 480px;
  height: 400px;
  position: relative;
  display: flex;
  z-index: 500;
}
.large {
  position: absolute;
  top: 0;
  left: 412px;
  width: 480px;
  height: 480px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.6);
  /* background-image: url(~@/assets/images/instagram-img-06.jpg); */
  background-repeat: no-repeat;
  background-size: 900px 900px;
  background-color: #f8f8f8;
}
.middle {
  width: 350px;
  height: 380px;
  background: #f3f1f1;
  box-shadow: 0 15px 10px -10px rgba(0, 0, 0, 0.8);
  position: relative;
  cursor: pointer;
  margin-left: 8px;
}
.middle>img{
  margin-left: 5px;
  width: 340px;
  height: 380px;
}
.layer {
  width: 200px;
  height: 200px;
  background: rgba(0, 0, 0, 0.2);
  left: 0;
  top: 0;
  position: absolute;
}

.small > li > img {
  width: 80px;
  height: 80px;
}
ul > li {
  width: 80px;
  height: 80px;
  margin-bottom: 20px;
  cursor: pointer;
}
.small > li:hover,
.active {
  border: 2px solid black;
}
nav {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 60px;
  background-color: black;
  margin: 0;
  padding: 0;
}
.demo-input-size {
  width: 200px;
  position: absolute;
  margin-left: 1450px;
  margin-top: 12px;
}
i {
  position: absolute;
  color: #b0b436;
  font-size: 22px;
  margin: 15px;
  cursor: pointer;
}
#car > img {
  width: 35px;
  height: 35px;
  position: absolute;
  margin-top: 10px;
  margin-left: 100px;
  cursor: pointer;
}
#search > img {
  width: 25px;
  height: 25px;
  position: absolute;
  margin-top: 16px;
  margin-left: 1620px;
  z-index: 1;
}
.common-layout {
  background-color: #f8f9fb;
}
h1 {
  text-align: center;
}
.row {
  text-align: center;
}
li {
  list-style: none;
}
a {
  text-decoration: none;
}
#listBox {
  display: flex;
  flex-wrap: wrap;
  margin-left: 130px;
}
.best-seller {
  width: 300px;
  height: 450px;
  background-color: aliceblue;
  /* margin:20px; */
  text-align: center;
  border: 1px solid rgb(192, 185, 185);
  cursor: pointer;
}
.best-seller img {
  width: 300px;
  height: 300px;
}
.sale {
  color: #b0b436;
  font-weight: bolder;
}
.new {
  color: #87da23;
  font-weight: bolder;
}
.mask-icon {
  width: 100px;
  height: 30px;
  background-color: #b0b436;
  margin-left: 100px;
  margin-top: 10px;
}
.mask-icon a {
  color: white;
  text-align: center;
}
#pageing {
  margin-left: 600px;
}
footer {
  width: 100%;
  height: 100%;
  background-color: black;
  color: white;
  /* margin-top:30px; */
}
.munber {
  width: 25px;
  height: 25px;
  position: absolute;
  border-radius: 50%;
  background-color: #a2f413;
  color: white;
  margin-left: 125px;
  z-index: 1;
}
.munber > p {
  position: absolute;
  font-weight: bolder;
  margin-top: 1px;
  margin-left: 7px;
}
.munber1 {
  width: 25px;
  height: 25px;
  position: absolute;
  border-radius: 50%;
  background-color: #a2f413;
  color: white;
  margin-left: 50px;
  z-index: 1;
}
.munber1 > p {
  position: absolute;
  font-weight: bolder;
  margin-top: 1px;
  margin-left: 7px;
}
nav > p {
  position: absolute;
  color: #b0b436;
  font-size: 22px;
  margin: 15px;
  cursor: pointer;
  margin-left: 170px;
}
.msg {
  position: absolute;
  margin-left: 500px;
  margin-top: -400px;
}
.msg > ul > li {
  margin-bottom: -30px;
  width: 450px;
  height: 80px;
}
.msg > ul > li > b {
  text-decoration-line: line-through;
}
#btn > img {
  width: 8px;
  height: 8px;
}
#btn {
  margin-top: 120px;
  position: absolute;
}
#btn2 {
  width: 150px;
  margin-top: 120px;
  position: absolute;
  margin-left: -160px;
}
.goods-sales {
  position: absolute;
  margin-left: 400px;
  margin-top: -180px;
}
.goods-sales > li {
  float: right;
  margin-left: 80px;
}
.headerBox {
  margin-top: 30px;
  border: 1px solid rgb(225, 223, 223);
  /* background-color:rgb(237, 231, 231); */
  height: 750px;
  width: 1200px;
  margin-left: 200px;
  padding-left: 80px;
}
hr {
  height: 4px;
  margin-right: 80px;
  background-color: #b0b436;
  /* margin-top: 50px; */
}
.addpage {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.mainpage {
  position: absolute;
  margin-left: 300px;
}
.middle > p {
  position: absolute;
  margin-top: 15px;
  font-size: 24px;
  font-weight: bolder;
}
#imgfooter2>p{
    font-size: 35px;
    font-weight: bolder;
    color:#b0b436;
    text-align: center;
    padding-top: 30px;
}
#imgfooter2 img{
    margin-left: 20px;
}
</style>
